//
//  SPManageListCell.swift
//  SparklingPets
//
//  Created by iOS-Czz on 2023/10/26.
//

import UIKit
import WMZDialog
class SPManageListCell: UITableViewCell {
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    @IBOutlet var timeLabel: UILabel!
    @IBOutlet var ratorLabel: UILabel!
    @IBOutlet var manageLabel: UILabel!
    @IBOutlet var nameLabel: UILabel!
    @IBOutlet var dateLabel: UILabel!
    @IBOutlet var completedLabel: UILabel!
    @IBOutlet var completedBtn: UIButton!
    @IBOutlet var rightPadding: NSLayoutConstraint!
    @IBOutlet var timeView: UIView!
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    var onDeleted: (() -> Void)?
    var onCompleted: (() -> Void)?
    override func layoutIfNeeded() {
        super.layoutIfNeeded()
        self.timeView.layer.borderWidth = 0
        self.timeView.addRoundCorners(topLeftRadius: 15, topRightRadius: 5, bottomLeftRadius: 5, bottomRightRadius: 15, borderWidth: 4, borderColor: .black)
    }
    var model: SPManageModel? {
        didSet {
            if model?.isCompleted == true {
                self.completedBtn.isHidden = true
                self.rightPadding.constant = 10
                self.completedLabel.isHidden = false
            }else{
                self.completedBtn.isHidden = false
                self.rightPadding.constant = 100
                self.completedLabel.isHidden = true
            }
            self.nameLabel.text = model?.name
            self.manageLabel.text = model?.manage
            self.ratorLabel.text = model?.rator
            self.timeLabel.text = model?.time
            self.dateLabel.text = model?.date
        }
    }
    @IBAction func clickDeleteAction(_ sender: Any) {
        let dialog = Dialog()
        dialog.wMessageSet()("After deletion, it cannot be restored. Are you sure to delete it？")
        .wOKTitleSet()("Sure")
        .wTitleSet()("Tips")
        .wCancelTitleSet()("Cancel")
        .wAutoCloseSet()(false)
        .wTypeSet()(DialogTypeNornal)
        .wEventCancelFinishSet()({(anyId:Any?,otherData:Any?)in
            WMZDialog.closeWithshowView(nil, block: nil)
        })
        .wEventOKFinishSet()({ [self](anyId:Any?,otherData:Any?)in
            onDeleted?()
            WMZDialog.closeWithshowView(nil, block: nil)
        })
        _ = dialog.wStart()
    }
    @IBAction func clickCompletedAction(_ sender: Any) {
        let dialog = Dialog()
        dialog.wMessageSet()("Are you sure you have completed this management？")
        .wOKTitleSet()("Sure")
        .wTitleSet()("Tips")
        .wCancelTitleSet()("Cancel")
        .wAutoCloseSet()(false)
        .wTypeSet()(DialogTypeNornal)
        .wEventCancelFinishSet()({(anyId:Any?,otherData:Any?)in
            WMZDialog.closeWithshowView(nil, block: nil)
        })
        .wEventOKFinishSet()({ [self](anyId:Any?,otherData:Any?)in
            onCompleted?()
            WMZDialog.closeWithshowView(nil, block: nil)
        })
        _ = dialog.wStart()
    }
    
    
}
